import { request } from 'ice';

export interface QueryParams {
  /** 类名 */
  clazz?: string;
  /** 方法名 */
  name?: string;
  /** 接口路径 */
  path?: string;
}

export interface ListVO {
  id: number;
  /** 名称 */
  name: string;
  /** 路径 */
  path: string;
  /** 方法资源 */
  method: string;
  /** 类名 */
  clazz: string;
  /** 备注 */
  remark: string;
  /** 系统模块 */
  sysModules: string;
}

/** 列表 */
export const apiList = (pageParams: ICommon.PageParams, formData: QueryParams): Promise<any> => {
  const params = {
    ...pageParams,
    ...formData,
  };
  return request.get('/erp/backend/uri/list', { params }).then((res) => ({
    total: res?.total || 0,
    list: res?.data || [],
  }));
};

/** 模块 */
export const modulesList = (): Promise<string[]> => {
  return request.get('/erp/backend/uri/modules');
};

/** 同步接口 */
export const apiSync = (): Promise<void> => {
  return request.get('/erp/backend/uri/sync');
};

/** 删除接口 */
export const apiDelete = (id?: number): Promise<void> => {
  return request.get('/erp/backend/uri/delete', { params: { id } });
};
